#pragma once

#include <portaudio.h>
#include "Decoder.h"

class SoundPlayer
{
public:
    SoundPlayer();
    ~SoundPlayer();
    
    void setSoundFile(const std::string& filename);

    void play();
    void stop();
    void pause();
    void resume();

    void setSpeed(float speed);
    float speed() const;

    void setVolume(float volume);
    float volume() const;

protected:
    void close();

    static int StreamCallback(
        const void *input, void *output,
        unsigned long frameCount,
        const PaStreamCallbackTimeInfo* timeInfo,
        PaStreamCallbackFlags statusFlags,
        void *userData);

    static void FinishedCallback(void *userData);

    virtual int streamCallback(const void *input, void *output,
        unsigned long frameCount,
        const PaStreamCallbackTimeInfo* timeInfo,
        PaStreamCallbackFlags statusFlags);

    virtual void finishedCallback();

    bool _valid;
    
    PaStream* _stream;
    Decoder<short>* _decoder;

    int _current;
    Sound<short>    _sound;

    float _speed;
    float _volume;
};

